package com.clstu.homework;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class Homework01Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9999);
        System.out.println("服务器端 9999端口 等待接入中.....");
        Socket socket = serverSocket.accept();

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        String s = bufferedReader.readLine();
        String answer = null;
        if(s.equals("name"))       answer = "along";
        else if(s.equals("hobby")) answer = "我喜欢编程！！！";
        else                       answer = "你说啥呢？？？？";
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bufferedWriter.write(answer);
        bufferedWriter.newLine();//表示会话结束
        bufferedWriter.flush();//把数据送入数据通道

        bufferedWriter.close();//关闭资源
        serverSocket.close();
        bufferedReader.close();


    }
}
